package com.itheima.mall.service.smsService;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pojo.sms.SmsCoupon;
import com.itheima.mall.commons.PageBean;
import com.itheima.mall.mapper.smsMapper.SmsCouponMapper;
import com.itheima.mall.service.smsService.SmsCouponServiceApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;


@DubboService
public class SmsCouponServiceImpl extends ServiceImpl<SmsCouponMapper, SmsCoupon> implements SmsCouponServiceApi {
    @Autowired
    private SmsCouponMapper smsCouponMapper;
    //添加优惠劵
    @Override
    public void createCoupon(SmsCoupon smsCoupon) {
        smsCouponMapper.insert(smsCoupon);
    }
    //删除
    @Override
    public void deleteCreate(Integer id) {
     smsCouponMapper.deleteById(id);
    }
    //根据优惠券名称和类型分页获取优惠券列表
    @Override
    public PageBean<SmsCoupon> getList(String name, Integer pageNum, Integer pageSize, Integer type) {
        IPage<SmsCoupon> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsCoupon> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(name !=null ,SmsCoupon::getName,name);
        queryWrapper.eq(type !=null ,SmsCoupon::getType,type);
        IPage<SmsCoupon> smsCouponIPage = smsCouponMapper.selectPage(page, queryWrapper);

        PageBean<SmsCoupon> pageBean = new PageBean<>(smsCouponIPage);
        return pageBean;
    }
    //更新优惠卷
    @Override
    public void updateByIds(SmsCoupon smsCoupon) {
        smsCouponMapper.updateById(smsCoupon);
    }
    //获取单个优惠卷的详细信息
    @Override
    public SmsCoupon getById(Integer id) {
        return smsCouponMapper.selectById(id);
    }
}





